package org.gnomus.data;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;

import java.util.ArrayList;
import java.util.List;

public class member extends object {

    public member(Entity e) {
        super(e);
        setFirstName((String) e.getProperty("first_name"));
        setLastName((String) e.getProperty("last_name"));
        setActive((Boolean) e.getProperty("active"));
    }

    public member(String first_name, String last_name) {
        super("member");
        setFirstName(first_name);
        setLastName(last_name);
        setActive(true);
    }

    public static List<member> fetch(Key gk) {
        List<member> members = new ArrayList<member>();
        for (link lnk : link.fetch("group", gk, "member", null)) {
            members.add(new member(store.get(lnk.getTargetKey())));
        }
        return members;
    }

    public void setFirstName(String first_name) {
        put("first_name", first_name);
    }

    public String getFirstName() {
        return (String) get("first_name");
    }

    public void setLastName(String last_name) {
        put("last_name", last_name);
    }

    public String getLastName() {
        return (String) get("last_name");
    }

    public void setActive(Boolean active) {
        put("active", active);
    }

    public Boolean isActive() {
        return (Boolean) get("active");
    }
}
